package com.hgq.tenadmin.sys.controller;

import com.hgq.tenadmin.sys.param.LoginParam;
import com.hgq.tenadmin.sys.service.UserService;
import com.hgq.tencommon.common.R;
import com.hgq.tencommon.entity.sys.SysUser;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.UUID;

@RestController
@RequestMapping("/sys/user")
public class UserController {
    @Resource
    private UserService userService;
    @PostMapping("/login")
    public R login(@RequestBody LoginParam loginParam, HttpSession session){
        SysUser login = userService.login(loginParam.getUsername(), loginParam.getPassword());
//        System.out.println(username+"===="+password);
        session.setAttribute("userInfo",login);

        //造假token
        HashMap<String, String> map = new HashMap<>();
        map.put("token", UUID.randomUUID().toString());
        return R.ok(map);
    }
    @GetMapping("/info")
    public R info(HttpSession session){
        SysUser userInfo = (SysUser)session.getAttribute("userInfo");
        return R.ok(userInfo);

    }
}
